﻿using System;
using System.Collections.Generic;
using HAVNet.Core;


namespace HAVNet.Intros.AST
{
    public class ASTExprPrimDelegate : ASTExprPrim
    {
        ASTAnonMethodParams _parameters = null;

        public bool                 hasParens   { get; set; } /* tiene parentesis? si no tiene parametros se puede escribir delegate {..} en vez de delegate () {..} */
        public ASTAnonMethodParams  parameters  { get { if (_parameters== null) _parameters = new ASTAnonMethodParams(); return _parameters; } }
        public ASTBlock             block       { get; set; }

        public override string ToString ()
        {
            // delegate         { ... }
            // delegate ()      { ... }
            // delegate (int x) { ... }

            if (hasParens)
                return
                    "delegate (" + Lazy.toStringNN(_parameters, "") + ")" + Environment.NewLine +
                    block +
                    Lazy.toStringNN(_tails, "");
            else
                return
                    "delegate " + Environment.NewLine +
                    block +
                    Lazy.toStringNN(_tails, "");
        }
    }
}
